package oa.hleast.xswl.controller.app.store;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.common.result.Result;
import oa.hleast.xswl.pojo.form.store.StoreRegisteredForm;
import oa.hleast.xswl.pojo.vo.store.BaseStoreInfo;
import oa.hleast.xswl.service.ISysUserService;
import oa.hleast.xswl.service.store.StoreInfoService;
import org.springframework.web.bind.annotation.*;


@Api(tags = "【移动端】商家信息表")
@RestController("AppStoreInfoController")
@RequestMapping("/api.app/v1/storeInfos")
@Slf4j
@AllArgsConstructor
public class StoreInfoController {

    private StoreInfoService storeInfoService;
    private final ISysUserService sysUserService;

    @ApiOperation(value = "商家注册 PC端注册", httpMethod = "POST")
    @PostMapping("/registeredByPC")
    public Result registeredByPC(@RequestBody StoreRegisteredForm form) {
        boolean status = storeInfoService.registeredByPC(form);
        return Result.judge(status);
    }

    @ApiOperation(value = "商家注册 移动端商家端注册", httpMethod = "POST")
    @PostMapping("/registeredByApp")
    public Result registeredByApp(@RequestBody StoreRegisteredForm form) {
        boolean status = storeInfoService.registeredByApp(form);
        return Result.judge(status);
    }

    @ApiOperation(value = "商店基本信息", httpMethod = "GET")
    @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataTypeClass = Long.class, dataType = "Long")
    @GetMapping("/baseInfo")
    public Result baseInfo(@RequestParam Long id) {
        BaseStoreInfo storeAndSpuVo = storeInfoService.baseInfo(id);
        return Result.success(storeAndSpuVo);
    }

    @ApiOperation(value = "检查是否用户名已被使用", httpMethod = "GET")
    @GetMapping("/checkRepeatUserName")
    public Result<Integer> checkRepeatUserName(@RequestParam String userName) {
        boolean isRepeat = sysUserService.checkRepeatUserName(userName);
        int result = isRepeat ? 1 : 0;

        return Result.success(result);
    }

}
